{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "sxzUiUosR0jC",
        "outputId": "e24334ff-eeb6-4ed4-d45e-09ca43e5a082"
      },
      "outputs": [],
      "source": [
        "!nvidia-smi"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "2iHOEg0pX4i8",
        "outputId": "67749e9c-e37f-4377-8eea-671aeac7922b"
      },
      "outputs": [],
      "source": [
        "from google.colab import drive\n",
        "\n",
        "drive.mount('/content/gdrive')"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "vjLvWMBvTeDh",
        "outputId": "2c47b68f-748d-466d-bc50-4863634d0f68"
      },
      "outputs": [],
      "source": [
        "%cd /content/gdrive/MyDrive/Drowsiness_detection_using_yolov5/"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "k9E7p5pKTH77",
        "outputId": "10d4d43f-f176-4f35-f2d3-2b4ed4bbcc3f"
      },
      "outputs": [],
      "source": [
        "!git clone https://github.com/ultralytics/yolov5  \n",
        "%cd yolov5\n",
        "!git reset --hard 064365d8683fd002e9ad789c1e91fa3d021b44f0"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "kgmB4SoFTKaP",
        "outputId": "3cafab58-66f9-4866-e876-1f4a4117c442"
      },
      "outputs": [],
      "source": [
        "%cd /content/gdrive/MyDrive/Drowsiness_detection_using_yolov5/yolov5\n",
        "!pip install -qr requirements.txt  \n",
        "import torch\n",
        "\n",
        "from IPython.display import Image, clear_output  \n",
        "from utils.downloads import attempt_download  \n",
        "\n",
        "print('Setup complete. Using torch %s %s' % (torch.__version__, torch.cuda.get_device_properties(0) if torch.cuda.is_available() else 'CPU'))\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "qHLY3SkOTU1a",
        "outputId": "1d7c8fd2-e2bc-4533-9792-fc6dc534b4d5"
      },
      "outputs": [],
      "source": [
        "%cd /content/gdrive/MyDrive/Drowsiness_detection_using_yolov5/yolov5"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "059TOEmIUDzt",
        "outputId": "749f6916-cf50-43b3-a5dd-c48334751172"
      },
      "outputs": [],
      "source": [
        "%cd /content/gdrive/MyDrive/Drowsiness_detection_using_yolov5/yolov5\n",
        "!wget https://github.com/ultralytics/yolov5/releases/download/v7.0/yolov5n.pt"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "3j4WMcrXT2Gq",
        "outputId": "01749f6d-d7fb-4dd4-db6e-3e17aae2717f"
      },
      "outputs": [],
      "source": [
        "dir_path = \"/content/gdrive/MyDrive/Drowsiness_detection_using_yolov5/yolov5\"\n",
        "%cd {dir_path}"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "N3cOqVwgVJMr",
        "outputId": "9dfeb653-149a-4bf1-c02c-9f84411d6255"
      },
      "outputs": [],
      "source": [
        "!python3 train.py --img 640 --batch 32 --epochs 25 --workers 8 --data {dir_path}/drowsiness_dataset/data.yaml --cfg {dir_path}/models/yolov5n.yaml --hyp {dir_path}/drowsiness_dataset/hyps/hyp.scratch-high.yaml --weights {dir_path}/yolov5n.pt --device 0\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "9yB_sBNO2n27",
        "outputId": "937c3355-e79d-4f27-b7b5-d5b38233024c"
      },
      "outputs": [],
      "source": [
        "dir_path = \"/content/gdrive/MyDrive/Drowsiness_detection_using_yolov5/yolov5\"\n",
        "%cd {dir_path}\n",
        "!python3 detect.py --weights {dir_path}/runs/train/exp3/weights/best.pt --conf 0.1 --source {dir_path}/testing/"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "colab": {
          "background_save": true,
          "base_uri": "https://localhost:8080/",
          "height": 1000
        },
        "id": "rb4tYptv2p-W",
        "outputId": "70641ae7-685b-47bc-8b17-4876ea4b0da3"
      },
      "outputs": [],
      "source": [
        "import glob\n",
        "from IPython.display import Image, display\n",
        "\n",
        "i = 0\n",
        "limit = 10000 \n",
        "dir_path = \"/content/gdrive/MyDrive/Drowsiness_detection_using_yolov5/yolov5\"\n",
        "%cd {dir_path}\n",
        "for imageName in glob.glob('/content/gdrive/MyDrive/Drowsiness_detection_using_yolov5/yolov5/runs/detect/exp/*.jp*'): \n",
        "    if i < limit:\n",
        "      display(Image(filename=imageName))\n",
        "      print(\"\\n\")\n",
        "    i = i + 1"
      ]
    }
  ],
  "metadata": {
    "colab": {
      "provenance": []
    },
    "kernelspec": {
      "display_name": "Python 3",
      "name": "python3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}
